;Copyright 2007-2010 Niko Carpenter and Tyler Spivey
;    This file is part of Linna Home Server.
;    Linna Home is free software: you can redistribute it and/or modify
;    it under the terms of the GNU General Public License as published by
;    the Free Software Foundation, either version 3 of the License, or
;    any later version.

;    Linna Home is distributed in the hope that it will be useful,
;    but WITHOUT ANY WARRANTY; without even the implied warranty of
;    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;    GNU General Public License for more details.

;    You should have received a copy of the GNU General Public License
;    along with Linna Home.  If not, see http://www.gnu.org/licenses/.

#include-once
#include <SRVLib.au3>
#include-once
TCPStartUp()
$Connection = TCPListen($LIP,$LPort,100)
if @Error Then
LogWrite("Error listening on "&$LIP&":"&$LPort&".")
Exit
EndIf
LogWrite("Listening on "&$LIP&":"&$LPort&".")
Func ConInit($i,$ac)
if not AllowCheck($ac) Then
Return 0
EndIf
if $i > uBound($Cons)-1 Then redim $cons[$i+1][$ar_max]
$Cons[$i][$C_User] = ""
$cons[$i][$C_Parser] = "auth_user"
$cons[$i][$C_REFilter] = ""
$cons[$i][$C_REFilterFlag] = 1
$Cons[$i][$C_FTPPid] = 0
$Cons[$i][$C_FTPFile] = ""
$Cons[$i][$C_FTPDir] = @ScriptDir
$cons[$i][$C_pdata] = ""
$cons[$i][$C_pdata2] = ""
$cons[$i][$C_pdata3] = ""
$cons[$i][$C_pdata4] = ""
$cons[$i][$C_pdata5] = ""
$cons[$i][$C_pdata6] = ""
$cons[$i][$C_pdata7] = ""
$Cons[$i][$C_Trust] = -1
$Cons[$i][$C_Working] = @ScriptDir
$cons[$i][$C_prompt] = "[%u@%h %w]%t"
if $ac >= 0 Then
LogWrite("Connected: "&SRVLib_SocketToIP($ac)&".")
TCPSend($ac,$WelcomeMsg&@CRLF)
TCPSend($ac,"User: ")
EndIf
return 1
EndFunc
Func dSend($id,$msg)
Return SRVLib_Send($id,$MSG)
EndFunc
Func ConClose($id)
$Cons[$id][$C_User] = ""
$Cons[$id][$C_Trust] = -1
$Cons[$id][$C_Working] = @ScriptDir
EndFunc
